package com.sinoglobal.dumping.activity;

import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.ProgressBar;

import com.sinoglobal.dumping.R;
import com.sinoglobal.dumping.base.Dumpling_SinoBaseActivity;
import com.sinoglobal.dumping.base.Dumpling_SinoConstans;

/**
 * Created by lxy on 2015/10/29.
 */
public class Dumpling_ActionRulesActivity extends Dumpling_SinoBaseActivity {

    private ImageView imgShare;
    private WebView mWeb;
    private ProgressBar progressBar;

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        setContentView(R.layout.dumpling_activity_actionrules);
        imgShare = getView(R.id.title_right_btn_share);
        hideViewForGone(imgShare, mTemplateRightImg);
        mTemplateTitleText.setText("活动规则");
        initView();

        WebSettings webSettings = mWeb.getSettings();
        // 设置WebView属性，能够执行Javascript脚本
        webSettings.setJavaScriptEnabled(true);
        // 设置可以访问文件
        webSettings.setAllowFileAccess(true);
        // 设置支持缩放
        webSettings.setBuiltInZoomControls(true);
        // 滚动条风格，0是不占用额外位置，覆盖到当前网页上
        mWeb.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
        // 加载需要显示的网页
        mWeb.loadUrl(Dumpling_SinoConstans.ACTION_RULES_URL);

        mWeb.setWebChromeClient(new WebChromeClient());
    }

    private void initView() {
        mWeb = getView(R.id.action_rules_web);
        progressBar = getView(R.id.action_rules_pro);
    }

    @Override
    public void onAntiViolence(View view) {

    }

    public class WebChromeClient extends android.webkit.WebChromeClient {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            if (newProgress == 100) {
                progressBar.setVisibility(View.GONE);
            } else {
                if (progressBar.getVisibility() == View.GONE)
                    progressBar.setVisibility(View.VISIBLE);
                progressBar.setProgress(newProgress);
            }
            super.onProgressChanged(view, newProgress);
        }

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
